//
//  KPFirstTableViewCell.swift
//  KPBaseProject
//
//  Created by Kipp Dev on 2018/3/24.
//  Copyright © 2018年 Kipp. All rights reserved.
//

import UIKit
import TangramKit

struct FirstCellModel {
    let headImage: String
    let name: String
    let time: String
    let detail: String
}

class KPFirstTableViewCell: UITableViewCell {

    var rootLayout:TGRelativeLayout!
    var headImage: UIImageView!
    var nameLabel: UILabel!
    var timeLabel: UILabel!
    var detailLabel: UILabel!

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        prepareView()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    // MARK: - 创建视图
    fileprivate func prepareView() {
        let re = TGRelativeLayout()
        re.tg_cacheEstimatedRect = true
        re.tg_width.equal(.fill)
        re.tg_height.equal(.wrap)
        re.tg_bottomPadding = 15
        rootLayout = re
        contentView.addSubview(re)

        headImage = UIImageView.init(image: placeholderHeadImage).then {
            $0.image = placeholderHeadImage
            $0.cornerRadius = 25
            $0.tg_width.equal(50)
            $0.tg_height.equal($0.tg_width)
            $0.tg_left.equal(15)
            $0.tg_top.equal(15)
            re.addSubview($0)
        }

        nameLabel = UILabel.init(text: nil, font: 15.font).then {
            $0.tg_left.equal(headImage.tg_right).offset(5)
            $0.tg_top.equal(headImage.tg_top).offset(4)
            $0.tg_height.equal(.wrap)
            $0.tg_width.equal(.wrap)
            re.addSubview($0)
        }

        timeLabel = UILabel.init(text: nil, font: 13.font, textColor: detailTextColor).then {
            $0.tg_left.equal(headImage.tg_right).offset(5)
            $0.tg_top.equal(nameLabel.tg_bottom).offset(8)
            $0.tg_height.equal(.wrap)
            $0.tg_width.equal(.wrap)
            re.addSubview($0)
        }

        detailLabel = UILabel.init(text: nil, font: 15.font).then {
            $0.numberOfLines = 0
            $0.tg_top.equal(headImage.tg_bottom).offset(10)
            $0.tg_left.equal(headImage.tg_left)
            $0.tg_right.equal(15)
            $0.tg_height.equal(.wrap)
            re.addSubview($0)
        }
    }

    // MARK: - 设置数据
    func setModel(_ model:FirstCellModel) {
//        headImage.kf.setHeadImage(model.headImage)
        nameLabel.text = model.name
        timeLabel.text = model.time
        detailLabel.text = model.detail
    }

}
